<?php
	include_once("appConfig.php");
	include_once("SCRIPTSbyABDULDAandME/DisplayStockStatus.php");
	$PagefunctionObjectMiddleTopInner=new siteFunctions();
	$GET_USERID=$PagefunctionObjectMiddleTopInner->SESSIONVALUE('DAILYpicksUserId');
	$DbObjectMiddleTopInner=CREATEdatabaseOBJECT();
	
	$GETsubMItvalUe=$PagefunctionObjectMiddleTopInner->POSTVALUE('Submit');
	
	if($GETsubMItvalUe != '' && $GETsubMItvalUe == 'Update')
	{
		$MAXloSSalertsValue=$PagefunctionObjectMiddleTopInner->POSTVALUE('MaxLoss');
		$FIrstSELlalertsValue=$PagefunctionObjectMiddleTopInner->POSTVALUE('FirstSell');
		$NExtLOssalertsValue=$PagefunctionObjectMiddleTopInner->POSTVALUE('NextLoss');
		$MUstSellalertsValue=$PagefunctionObjectMiddleTopInner->POSTVALUE('MustSell');
		$SYmbOlNamE=$PagefunctionObjectMiddleTopInner->POSTVALUE('COMpanySYmbol');
		$FEAturedInfo=$PagefunctionObjectMiddleTopInner->POSTVALUE('Featured');
		
		$selECtOtherFeatured="SELECT `recordId`,`companySymbol`,`userId` FROM ".USERSTOCKPREFERANCE." WHERE `userId` ='".$GET_USERID."'";
		$execUTiONOFselECtOtherFeatured=$DbObjectMiddleTopInner->sql_query($selECtOtherFeatured);
		if($DbObjectMiddleTopInner->sql_numrows($execUTiONOFselECtOtherFeatured) > 0)
		{
			while($RESULTofexecUTiONOFselECtOtherFeatured=$DbObjectMiddleTopInner->sql_fetchrow($execUTiONOFselECtOtherFeatured))
			{
				//echo $FEAturedInfo.'<br><br>';
				if($FEAturedInfo != '')
				{
					//echo $RESULTofexecUTiONOFselECtOtherFeatured['companySymbol'] .'=='. $SYmbOlNamE.'<br><br>';
					if($RESULTofexecUTiONOFselECtOtherFeatured['companySymbol'] == $SYmbOlNamE)
					{
						$UPdatEPrefferAnce="UPDATE ".USERSTOCKPREFERANCE." SET `maxLossAlerts`='".$MAXloSSalertsValue."',
															`firstSellAlerts`='".$FIrstSELlalertsValue."',
															`nextLossAlerts`='".$NExtLOssalertsValue."',
															`mustSellAlerts`='".$MUstSellalertsValue."', 
															`isFeatured` = 'Y'";
															
						$UPdatEPrefferAnce.=" WHERE `companySymbol`='".$SYmbOlNamE."' AND `userId`='".$GET_USERID."'";
					}
					else
					{
						$UPdatEPrefferAnce="UPDATE ".USERSTOCKPREFERANCE." SET `isFeatured` = 'N' WHERE `companySymbol`='".$RESULTofexecUTiONOFselECtOtherFeatured['companySymbol']."' AND `userId`='".$GET_USERID."'";
						
					}
				}
				else
				{
					if($RESULTofexecUTiONOFselECtOtherFeatured['companySymbol'] == $SYmbOlNamE)
					{
						$UPdatEPrefferAnce="UPDATE ".USERSTOCKPREFERANCE." SET `maxLossAlerts`='".$MAXloSSalertsValue."',
															`firstSellAlerts`='".$FIrstSELlalertsValue."',
															`nextLossAlerts`='".$NExtLOssalertsValue."',
															`mustSellAlerts`='".$MUstSellalertsValue."', 
															`isFeatured` = 'N'";
															
						$UPdatEPrefferAnce.=" WHERE `companySymbol`='".$SYmbOlNamE."' AND `userId`='".$GET_USERID."'";
					}
					
				}
				//echo $UPdatEPrefferAnce.'<br><br>';
				$DbObjectMiddleTopInner->sql_query($UPdatEPrefferAnce);
			}
		}
		$PagefunctionObjectMiddleTopInner->RedirectPageTo("PageGo");
	}
	
	
	
	$SELECT_user_Prefferance="SELECT * FROM ".USERSTOCKPREFERANCE." WHERE `userId`='".$GET_USERID."'";
	//echo $SELECT_user_Prefferance.'<br><br>';
	$EXECUTIONofSELECT_user_Prefferance=$DbObjectMiddleTopInner->sql_query($SELECT_user_Prefferance);
	$StructuReForFeatured='<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">';
	$StructuReForNonFeatured='<table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">';
	$ISFEAtuREd=0;
	//print_r($SYMBOLNAme);
	if($DbObjectMiddleTopInner->sql_numrows($EXECUTIONofSELECT_user_Prefferance) > 0)
	{
		$COUnteR=1;
		while($ResuLTofEXECUTIONofSELECT_user_Prefferance = $DbObjectMiddleTopInner->sql_fetchrow($EXECUTIONofSELECT_user_Prefferance))
		{
			if($ResuLTofEXECUTIONofSELECT_user_Prefferance['isFeatured'] == 'Y')
			{
				if(array_key_exists($ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'],$SYMBOLNAme))
				{
					$ImgFeatured=$SYMBOLNAme[$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol']];
				}
				else
				{
					$ImgFeatured='Yellow.png';
				}

				if(array_key_exists($ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'],$STOCKsymbolOpening))
				{
					$TodAys_Opening=$STOCKsymbolOpening[$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol']];
				}
				else
				{
					$TodAys_Opening='0.00';
				}

				if(array_key_exists($ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'],$STOCKsymbolLastvaLue))
				{
					$Todays_LAStvalUe=$STOCKsymbolLastvaLue[$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol']];
				}
				else
				{
					$Todays_LAStvalUe='0.00';
				}


						 
						 $StructuReForFeatured.='<tr>
							  <td align="left" valign="top"><img src="GRAPHS/Big.png" /></td>
						</tr>
					     <tr>
					       <td align="left" valign="top"><img src="GRAPHS/big/'.$ImgFeatured.'" id="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'_image" /></td>
				          </tr>
					     <tr>
					       <td align="left" valign="top">&nbsp;</td>
				          </tr><td align="center" colspan="3">
						  <form name="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'_Submit" id="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'_Submit" method="post" action="" onSubmit="return PreFFCheck(\''.$COUnteR.'\',\'Update\');" >
							<table width="100%" border="0" cellspacing="2" cellpadding="0">
							  <tr>
								<td colspan="6" class="SITEtext">For Symbol : '.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'</td>
							  </tr>
							  <tr>
								<td valign="middle"><input name="MaxLoss" type="text" id="MaxLoss'.$COUnteR.'" size="8" maxlength="6" class="MaxLossClass SITEtext" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['maxLossAlerts'].'" title="Maximum Loss SITEtext"></td>
								<td valign="middle"><input name="FirstSell" type="text" id="FirstSell'.$COUnteR.'" size="8" maxlength="6" class="FirstSellClass SITEtext" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['firstSellAlerts'].'" title="First Sell"></td>
								<td valign="middle"><input name="NextLoss" type="text" id="NextLoss'.$COUnteR.'" size="8" maxlength="6" class="NextLossClass SITEtext" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['nextLossAlerts'].'" title="Next Loss"></td>
								<td valign="middle"><input name="MustSell" type="text" id="MustSell'.$COUnteR.'" size="8" maxlength="6" class="MustSellClass SITEtext" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['mustSellAlerts'].'" title="Must Sell"></td>
								
							    <td valign="middle" class="SITEtext"><input type="checkbox" name="Featured" id="Featured" value="Y" checked="checked"> Featured</td>
								
							  </tr>
							  <tr>
								<td colspan="6" id="PreFFChoiceError'.$COUnteR.'" style="display:none;" >
								<span id="PreFFChoiceError_1_'.$COUnteR.'" style="color:#FF0000; font-weight:bold; font-size:11px;"></span>			</td>
							  </tr>
							  <tr>
								<td class="SITEtext" colspan="3">
								<table width="100%" border="0" cellspacing="0" cellpadding="1">
								  <tr>
									<td class="SITEtext">Opening Price: <span class="SITEtextNormal">'.$TodAys_Opening.'</span></td><td class="SITEtext">Current Price: <span id="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'_LastvaLue" class="SITEtextNormal">'.$Todays_LAStvalUe.'</span></td>
								  </tr>
								</table>
								</td>
								<td colspan="2"><input type="submit" name="Submit" value="Update" class="LoginInputButton"><input type="hidden" name="COMpanySYmbol" id="COMpanySYmbol" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'""></td>
							  </tr>
						  </table>
						 </form>
						 </td>';
						  $ISFEAtuREd=1;
				
			}
			else
			{
				if(array_key_exists($ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'],$SYMBOLNAme))
				{
					//echo $ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'];
					$ImgNotFeatured=$SYMBOLNAme[$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol']];
				}
				else
				{
					$ImgNotFeatured='Yellow.png';
				}
				
				if(array_key_exists($ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'],$STOCKsymbolOpening))
				{
					$TodAys_Opening=$STOCKsymbolOpening[$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol']];
				}
				else
				{
					$TodAys_Opening='0.00';
				}

				if(array_key_exists($ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'],$STOCKsymbolLastvaLue))
				{
					$Todays_LAStvalUe=$STOCKsymbolLastvaLue[$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol']];
				}
				else
				{
					$Todays_LAStvalUe='0.00';
				}
				$StructuReForNonFeatured.='<tr>
								<td width="56%" align="center"><img src="GRAPHS/small.png" /></td>
								<td width="44%" align="center"><img src="GRAPHS/small/'.$ImgNotFeatured.'" id="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'_image" /></td>
							 </tr><tr>
      <td align="center" colspan="3" valign="top">
	  <form name="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'_Submit" id="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'_Submit" method="post" action="" onSubmit="return PreFFCheck(\''.$COUnteR.'\',\'Update\');" >
	  	<table width="100%" border="0" cellspacing="2" cellpadding="0">
          <tr>
            <td colspan="5" class="SITEtext">For Symbol : '.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'</td>
          </tr>
          <tr>
            <td valign="middle"><input name="MaxLoss" type="text" id="MaxLoss'.$COUnteR.'" size="8" maxlength="6" class="MaxLossClass SITEtext" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['maxLossAlerts'].'" title="Maximum Loss SITEtext"></td>
            <td valign="middle"><input name="FirstSell" type="text" id="FirstSell'.$COUnteR.'" size="8" maxlength="6" class="FirstSellClass SITEtext" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['firstSellAlerts'].'" title="First Sell"></td>
            <td valign="middle"><input name="NextLoss" type="text" id="NextLoss'.$COUnteR.'" size="8" maxlength="6" class="NextLossClass SITEtext" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['nextLossAlerts'].'" title="Next Loss"></td>
            <td valign="middle"><input name="MustSell" type="text" id="MustSell'.$COUnteR.'" size="8" maxlength="6" class="MustSellClass SITEtext" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['mustSellAlerts'].'" title="Must Sell"></td>
            <td valign="middle" class="SITEtext"><input name="Featured" type="checkbox" id="Featured" value="Featured"> 
            Featured </td>
          </tr>
		  <tr>
		  	<td colspan="5" id="PreFFChoiceError'.$COUnteR.'" style="display:none;" >
			<span id="PreFFChoiceError_1_'.$COUnteR.'" style="color:#FF0000; font-weight:bold; font-size:11px;"></span>			</td>
		  </tr>
          <tr>
            <td class="SITEtext" colspan="3">
			<table width="100%" border="0" cellspacing="0" cellpadding="1">
			  <tr>
				<td class="SITEtext">Opening Price: <span class="SITEtextNormal">'.$TodAys_Opening.'</span></td><td class="SITEtext">Current Price: <span id="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'_LastvaLue" class="SITEtextNormal">'.$Todays_LAStvalUe.'</span></td>
			  </tr>
			</table>
			</td>
            <td colspan="2"><input type="submit" name="Submit" value="Update" class="LoginInputButton"><input type="hidden" name="COMpanySYmbol" id="COMpanySYmbol" value="'.$ResuLTofEXECUTIONofSELECT_user_Prefferance['companySymbol'].'"></td>
          </tr>
      </table>
	 </form>
	 </td>
    </tr>';
			}
			$COUnteR++;
		}
		
	}
	else
	{
		$StructuReForNonFeatured.='<tr>
				 <td align="center" valign="top" style="font-weight:bold; font-size:14px; color:#FF0000; ">You have not preffered any Symbol !</td>
			</tr>';
		

	}
	if($ISFEAtuREd == 0 )
	{
		$StructuReForFeatured='<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0"><tr>
				 <td align="center" valign="top" style="font-weight:bold; font-size:14px; color:#FF0000; ">You have not featured any Symbol !</td>
			</tr>';
	}
	$StructuReForFeatured.='</table>';
	$StructuReForNonFeatured.='</table>';
	include_once $PagefunctionObjectMiddleTopInner->inputHTML('actionbodyMiddleTopInnerUser');
?>
